//
//  JgAdsSplashAdContainer.m
//  AnyThinkSDKDemo
//
//  Created by 李上京 on 2022/11/14.
//  Copyright © 2022 抽筋的灯. All rights reserved.
//

#import "JgAdsSplashAdContainer.h"

@interface JgAdsSplashAdContainer()<JgAdsSplashAdDelegate>

@property(nonatomic, strong) JgAdsSplashAd *splashAd;

@end

@implementation JgAdsSplashAdContainer
-(void)setDelegate:(id<JgAdsSplashAdDelegate>)delegate{
    self.splashAd.delegate = delegate;
}
// MARK: - Init
-(instancetype)initPosId:(NSString *)posId delegate:(id<JgAdsSplashAdDelegate>)delegate{
    self = [super init];
    if(self){
        self.splashAd = [JgAdsSplashAd new];
        self.splashAd.posId = posId;
        self.splashAd.delegate = delegate;
        if (delegate == nil) {
            self.splashAd.delegate = self;
        }
    }
    return self;
}
- (void)loadAdWithBottomView:(UIView *)bottomView{
    [_splashAd loadAdWithBottomView:bottomView];
}
- (void)showAdInWindow:(UIWindow *)window withBottomView:(nullable UIView *)bottomView{
    [_splashAd showInWindow:window];
}
- (void)loadAndShowInWindow:(UIWindow *)window withBottomView:(nullable UIView *)bottomView{
    [_splashAd loadAndShowInWindow:window withBottomView:bottomView];
}
- (void)sendWinNotificationWithPrice:(NSInteger)price{
    [_splashAd sendWinNotificationWithPrice:price];
}
- (void)sendWinFailNotificationReason:(JgAdsBiddingLossReason)lossReason winnerPirce:(NSInteger)winnerPirce{
    [_splashAd sendWinFailNotificationReason:lossReason winnerPirce:winnerPirce];
}
-(void)close{
    _splashAd = nil;
}
- (NSInteger)getBidPrice{
    return _splashAd.bidPrice;
}
#pragma mark -- JgAdsSplashAdDelegate
/**
 *  开屏广告素材加载成功
 */
- (void)JgAdsSplashAdDidLoad:(JgAdsSplashAd *)splashAd {
#if DEBUG
        NSLog(@"jgads============开屏广告-加载成功");
#endif
    if ([self.containerDelegate respondsToSelector:@selector(jgadsContainer_jgadsSplashAdDidLoad:withPrice:)]) {
        [self.containerDelegate jgadsContainer_jgadsSplashAdDidLoad:self withPrice:splashAd.bidPrice];
    }
}

/**
 *  开屏广告请求失败
 */
- (void)JgAdsSplashAdFailLoad:(JgAdsSplashAd *)splashAd withError:(NSError *)error{
#if DEBUG
        NSLog(@"jgads============开屏广告-加载失败：%@",error);
#endif
    if ([self.containerDelegate respondsToSelector:@selector(jgadsContainer_jgadsSplashAdFailLoadError:)]) {
        [self.containerDelegate jgadsContainer_jgadsSplashAdFailLoadError:error];
    }
}
@end
